/** 
    ____                            
   / __ )_________ __   _____  _____
  / __  / ___/ __ `/ | / / _ \/ ___/
 / /_/ / /  / /_/ /| |/ /  __/ /    
/_____/_/   \__,_/ |___/\___/_/     
* @Title: CacheRunner.java 
* @Package soft.ay.qram 
* @Description: 缓存接口
* @author vsuns 
* @date 2019年5月25日 
* @version V1.0 
*/ 
package soft.ay.qram;

import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;

/**  
*  
*/
public interface ICacheLoader
{
    //接口中定义的变量，默认为静态常量
    // 属性部分
    String INSERT_TO_KV = "INSERT INTO kv_table (string_key, string_value) VALUES ('%s', '%s')";
    String UPDATE_TO_KV = "UPDATE kv_table SET string_value = '%s' WHERE string_key='%s'";
    String SELECT_FROM_KV = "SELECT string_value FROM kv_table WHERE string_key='%s' LIMIT 1";
    String SELECT_KEYS_FROM_KV = "SELECT string_key FROM kv_table";
    String COUNT_KEYS_FROM_KV = "SELECT COUNT(string_key) FROM kv_table WHERE string_key='%s'";
    String DELETE_FROM_KV = "DELETE FROM kv_table WHERE string_key='%s'";
    String MATCH_KEYS_FROM_KV = "SELECT string_key FROM kv_table WHERE string_key like '%s'";
    String SELECT_FROM_KV_BY_MATCH_KEY = "SELECT string_key,string_value FROM kv_table WHERE string_key like '%s'";

    String INSERT_TO_KV_TIME = "INSERT INTO kv_time_table (string_key, string_value, expire_time) VALUES ('%s', '%s', %d)";
    String UPDATE_TO_KV_TIME = "UPDATE kv_time_table SET string_value = '%s',expire_time = %d WHERE string_key = '%s'";
    String SELECT_FROM_KV_TIME = "SELECT string_value FROM kv_time_table WHERE string_key='%s' AND expire_time>=%d LIMIT 1";
    String SELECT_KEYS_FROM_KV_TIME = "SELECT string_key FROM kv_time_table WHERE expire_time>=%d";
    String COUNT_KEYS_FROM_KV_TIME = "SELECT COUNT(string_key) FROM kv_time_table WHERE string_key='%s' and expire_time>=%d";
    String DELETE_FROM_KV_TIME = "DELETE FROM kv_time_table WHERE string_key='%s'";
    String MATCH_KEYS_FROM_KV_TIME = "SELECT string_key FROM kv_time_table WHERE expire_time>=%d and string_key like '%s'";
    String SELECT_FROM_KV_TIME_BY_MATCH_KEY = "SELECT string_key,string_value FROM kv_time_table WHERE string_key like '%s' AND expire_time>=%d";
    String DELETE_EXPIRE_FROM_KV_TIME = "DELETE FROM kv_time_table WHERE expire_time<%d";
    // 持久缓存，无失效时间
    void addToCache(String key, String value);

    // 暂时，指定存活时间
    void addToCache(String key, String value, TimeUnit unit, Long expire);

    // 从持久缓存获取
    String getFromCache(String key);

    // 获取所有key
    Set<String> getKeys();

    // 检查key
    Boolean containKey(String key);

    // 删除key
    void removeKey(String key);

    // 设置有效期
    void expireKey(String key, TimeUnit unit, Long expire);

    // 永久生效
    void persistKey(String key);

    // 后模糊匹配key，like ‘key%’
    Set<String> matchKey(String key);

    // 后模糊匹配key，like ‘key%’，获得值
    Map<String, String> getFromCacheByMatchKey(String key);
    /// 还有其他接口待添加 TODO

}
